<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>表单样式</title>
    <style type="text/css">
    div{
        margin: 10px;
    }
    input{
        width: 400px;
        height: 30px;
        border: 1px solid #ccc;
    }
    .focus{
        border: #f00 solid 1px;
        background: #f0f0f0;
    }
    </style>
    <script src="JS/jquery-3.3.1.js" type="text/javascript"></script>
    <script type="text/javascript">    
        $(function() {
            var _str= $(this).val(); 
            $(":input").focus(function(){//获取焦点
                $(this).addClass("focus");
                
                $(this).val("");

            }).blur(function(){//失去焦点
                $(this).removeClass("focus");

                if($(this).val() == "")
                {
                    //$(this).val(_str);
                    $(this).val(this.defaultValue);
                }
            });
        });
    </script>
</head>
<body>    
    <div>
        <label for="username">登录代码:</label>
        <input id="username" type="text" value="登录代码" />
    </div>
    <div>
        <label for="pass">用户密码:</label>
        <input id="pwd" type="password" value="用户密码" />
    </div>
    <div>
        <label for="msg">详细信息:</label>
        <textarea id="msg" rows="2" cols="20">详细信息</textarea>
    </div>

</body>
</html>